package logic

import (
	"context"
	"encoding/json"
	"fmt"
	"time"
	"video-management-system/cache"
	"video-management-system/model"

	"video-management-system/userrpc/internal/svc"
	"video-management-system/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoListLogic {
	return &VideoListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 视频列表
func (l *VideoListLogic) VideoList(in *userrpc.VideoListRequest) (*userrpc.VideoListResponse, error) {
	// todo: add your logic here and delete this line
	var list []*userrpc.VideoList
	key := fmt.Sprintf("VideoList%v", in)

	list = model.VideoList(model.DB, in)
	marshal, _ := json.Marshal(&list)
	cache.Rdb.Set(l.ctx, key, marshal, time.Minute*10)

	return &userrpc.VideoListResponse{
		List: list,
	}, nil
}
